package easy.id_601_700;

import java.util.ArrayList;
import java.util.List;

// 有点东西，值得回味
public class Lee696 {
    public int countBinarySubstrings(String s) {
        List<Integer> counts=new ArrayList<>();
        int ptr = 0, n = s.length();
        while (ptr < n) {
            char c = s.charAt(ptr);
            int count = 0;
            while (ptr < n && s.charAt(ptr) == c) {
                ++ptr;
                ++count;
            }
            counts.add(count);
        }
        int sum=0;
        for(int i=1;i<counts.size();i++){
            sum+=(Math.min(counts.get(i),counts.get(i-1)));
        }
        return sum;
    }
}
